﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using nwrole.Orchestrator.site.Models;
using nwrole.Orchestrator.site.Utils;
using nwrole.lib;

namespace nwrole.Orchestrator.site.Controllers
{
    public class LogController : Controller
    {
        //
        // GET: /Log/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Show(Guid id)
        {
            LogShowViewModel viewModel = new LogShowViewModel();

            using (TcpRelayChannel<IOrchestratorCtrlChannel> tcpRelayChannel = new TcpRelayChannel<IOrchestratorCtrlChannel>(SiteSettings.OrchestratorSBServiceNamespace, SiteSettings.OrchestratorSBServicePath, SiteSettings.OrchestratorSBIssuerName, SiteSettings.OrchestratorSBIssuerSecret))
            {
                viewModel.LogMessages = tcpRelayChannel.Channel.GetLogForObject(id);

                /*SupervisorInfo[] supervisorInfos = tcpRelayChannel.Channel.GetRegisteredSupervisors();
                viewModel.SupervisorInfo = supervisorInfos.SingleOrDefault(s => s.Id == id);
                if (viewModel.SupervisorInfo != null)
                    viewModel.ServicesInfo = tcpRelayChannel.Channel.GetSupervisorServicesInfo(viewModel.SupervisorInfo.Id);

                if (viewModel.ServicesInfo == null)
                    viewModel.ServicesInfo = new List<ServiceInfo>();*/

                /*SupervisorData[] supervisorDatas = tcpRelayChannel.Channel.GetSupervisors();
                viewModel.SupervisorData = supervisorDatas.SingleOrDefault(s => s.Id == id);
                if(viewModel.SupervisorData != null)
                    viewModel.ServicesInfo = tcpRelayChannel.Channel.GetSupervisorServicesInfo(viewModel.SupervisorData.Id);
                else
                    viewModel.ServicesInfo = new List<ServiceInfo>();*/
            }

            if(viewModel.LogMessages == null)
                viewModel.LogMessages = new LogMessage[0];

            return View(viewModel);
        }

    }
}
